Skip to content

Conversation

@partcyborg
Copy link

@partcyborg partcyborg commented Jul 17, 2024

Description

Adds parameter tgw_additional_vpc_cidrs to the vpc_attachments map that enables adding additional aws_route resources that send traffic across the TGW VPC attachment.

Changes the name of the existing aws_route resource from this since there are now more than one in the state file.

Motivation and Context

In our environment we have two CIDR blocks that need to transit from the VPC across the TGW network: 10.0.0.0/8 and 172.16.0.0/12. Unfortunately this is not possible to do with the module as it is today.

With this change we can add aws_route entries for both CIDR blocks to our VPC route tables.

Breaking Changes

In order to implement this I had to add a second aws_route resource because the existing one is keyed only on route table ID which is no longer a unique value for route resources.

Commonly accepted Terraform style rules indicate that this is only an acceptable resource name if it is the only one of its type in a module. Since there are now two aws_route resources, I changed the name of the existing this resource to destination_cidr so that this style rule is still valid.

While I personally feel that the this is the correct approach, if renaming the resource is undesirable I would fine with reverting the resource rename.

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@partcyborg
Copy link
Author

NOTE: this change has the same bootstrapping problem as #111, but it works correctly when the VPC resources are configured ahead of time (or in a separate state file as we do in our terraform)

@elopsod
Copy link

elopsod commented Jul 24, 2024

Hi @antonbabenko could you please take a look
Thank you!

@matkovskiy
Copy link

Good morning.
@antonbabenko Could you take a look at that?
I am also waiting for this functionality

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Sep 13, 2024
@elkh510
Copy link

elkh510 commented Sep 13, 2024

Hi @antonbabenko could you please take a look
Thank you!

@github-actions github-actions bot removed the stale label Sep 14, 2024
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Oct 14, 2024
@elkh510
Copy link

elkh510 commented Oct 14, 2024

Hi
Still actually

@github-actions github-actions bot removed the stale label Oct 15, 2024
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Nov 15, 2024
@elkh510
Copy link

elkh510 commented Nov 15, 2024

Hi
Still actually

@github-actions github-actions bot removed the stale label Nov 16, 2024
@partcyborg
Copy link
Author

pinging this again. @antonbabenko were you able to look at this? Or @elkh510 is there someone else that can?

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Jan 13, 2025
@elopsod
Copy link

elopsod commented Jan 13, 2025

Hi
Still actually

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Feb 13, 2025
@elopsod
Copy link

elopsod commented Feb 13, 2025

Hi
Still actually

@github-actions github-actions bot removed the stale label Feb 14, 2025
@stankevicius
Copy link

Hello,

Do you know if there's any progress on the review? Waiting for this implementation.

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Apr 10, 2025
@elopsod
Copy link

elopsod commented Apr 10, 2025

Hi
Still actually

@github-actions github-actions bot removed the stale label Apr 11, 2025
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label May 11, 2025
@elkh510
Copy link

elkh510 commented May 11, 2025

Hi
Still actually

@github-actions github-actions bot removed the stale label May 12, 2025
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Jun 12, 2025
@elkh510
Copy link

elkh510 commented Jun 12, 2025

Hi
Still actually

@github-actions github-actions bot removed the stale label Jun 13, 2025
@pongsakfreshket
Copy link

Hi Please verify and merge please

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Jul 20, 2025
@elkh510
Copy link

elkh510 commented Jul 20, 2025

Hi
Still actually

@github-actions github-actions bot removed the stale label Jul 21, 2025
@partcyborg partcyborg force-pushed the additional-vpc-cidr-blocks branch from d4618e1 to 466ee64 Compare July 25, 2025 22:43
@partcyborg
Copy link
Author

Hi Please verify and merge please

Hey @pongsakfreshket i need an approval from someone authorized on this project. Unfortunately it looks like your approval doesn't count here as I still can't merge.

@elkh510
Copy link

elkh510 commented Aug 23, 2025

Hi
Still actually

@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Sep 23, 2025
@elkh510
Copy link

elkh510 commented Sep 23, 2025

Hi
Still actually

Adds parameter `tgw_additional_vpc_cidrs` to the `vpc_attachments` map that enables adding additional `aws_route` resources that send traffic across the TGW peering connection.

Changes the name of the existing `aws_route` resource from `this` since there are now more than one in the state file.
@partcyborg partcyborg force-pushed the additional-vpc-cidr-blocks branch from 466ee64 to 6d7820c Compare October 16, 2025 00:00
@partcyborg
Copy link
Author

Hello @antonbabenko I have re-based this PR to match the recent changes

Copy link
Contributor

@yyarmoshyk yyarmoshyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonbabenko I think this is very important change.

@partcyborg please check my comments.

transit_gateway_attachment_id = tobool(try(local.vpc_attachments_with_routes[count.index][1].blackhole, false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0].key].id : null
}

resource "aws_route" "this" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to introduce additional resources resource "aws_route" "additional_cidrs" and resource "aws_route" "destination_cidr"

Let's simplify the code a bit by looping over the merged map of local.vpc_route_table_destination_cidr and local.vpc_route_table_additional_cidrs like the following:

resource "aws_route" "this" {
  for_each = { for x in merge(local.vpc_route_table_destination_cidr,local.vpc_route_table_additional_cidrs) : ${x.rtb_id}_${x.cidr} => {
    cidr   = x.cidr,
    tgw_id = x.tgw_id
    rtb_id = x.rtb_id
  } }

  region = var.region

  route_table_id              = each.value["rtb_id"]
  destination_cidr_block      = try(each.value.ipv6_support, false) ? null : each.value["cidr"]
  destination_ipv6_cidr_block = try(each.value.ipv6_support, false) ? each.value["cidr"] : null
  transit_gateway_id          = each.value["tgw_id"]

  depends_on = [aws_ec2_transit_gateway_vpc_attachment.this]
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yyarmoshyk this change isn't possible without causing the deletion of all existing aws_route.this resources, as you can't do dynamic moved blocks.

Given that the key for the default route will depend on the current cidr block, there is no way to write a moved block that will move the existing route entry into a key for the current aws_route.this resource.

As I stated in the PR description, this leaves us only two options:

  1. Keep the aws_route.this resource as is, but add the aws_route.additional_cidrs resource which has a map with key. This violates terraform style, but if we want to drop the moved block I would be okay with that if the module owners are okay with ignoring terraform style.
  2. Keep the change as written which allows us to not destroy the existing route resource but move it to the new entry, while also keeping the additional_cidrs object which is a map.

If we just do what you suggest, I would have to remove the moved block which would mean that when users upgrade the terraform module the route entry will be deleted and re-created which could cause traffic disruption. This is highly undesirable in my opinion

depends_on = [aws_ec2_transit_gateway_vpc_attachment.this]
}

moved {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the change above this becomes unneeded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated above, your suggestion will cause an outage for all users of this module. I really don't think this is the right approach here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants